<?php
$numSeg = $_POST['numero'];
?>
<table border="1">
    <tr>
        <td>Numero del paquete</td>
        <td>Volumen</td>
        <td>Numero de paquetes</td>
        <td>Notas</td>
    </tr>
    <?php obtenerPaquete($numSeg) ?>
</table>
<?php
obtenerSecciones($numSeg);

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function obtenerNumeroSecciones($numSeg) {
    $conn = conectarDb();
    $sql = "Select count(*) from shipment_section where shipment_idShipment=$numSeg";
    $result = mysql_query($sql);
    $linea = mysql_fetch_array($result, MYSQL_ASSOC);
    return $linea['count(*)'];
}

function conectarDb() {
    if (!($link = mysql_connect("localhost:3306", "root", "root"))) {
        echo "Error conectando a la base de datos.";
        exit();
    }
    if (!mysql_select_db("mercawar", $link)) {
        echo "Error seleccionando la base de datos.";
        exit();
    }
    return $link;
}

function obtenerSecciones($numSeg) {
    $conn = conectarDb();
    $sql = "Select * from shipment_section, section where shipment_section.shipment_idShipment=$numSeg and shipment_section.section_idSection=IdSection";
    $result = mysql_query($sql);

    $numeroSecciones = obtenerNumeroSecciones($numSeg);
        ?>
        <table>
            <tr>
                <td align="center">Num seccion</td>
                <td align="center">Km</td>
                <td align="center">precio</td>
            </tr>
            <?php
            for ($i = 0; $i < $numeroSecciones; $i++) {
                $linea = mysql_fetch_array($result, MYSQL_ASSOC);
                ?>
                <tr>
                    <td align="center"><?php echo $linea['idSection'] ?></td>
                    <td align="center"><?php echo $linea['km'] ?></td>
                    <td align="center"><?php echo $linea['price'] ?></td>
                </tr>
            <?php
    }
    ?>
    </table>
        <?php
    }

    function obtenerPaquete($numSeg) {
        $conn = conectarDb();
        $sql = "Select * from shipment where idShipment=$numSeg ";
        $result = mysql_query($sql);
        $linea = mysql_fetch_array($result, MYSQL_ASSOC);
        ?>
    <tr>
        <td align="center"><?php echo $linea['idShipment'] ?></td>
        <td align="center"><?php echo $linea['number_packages'] ?></td>
        <td align="center"><?php echo $linea['volume'] ?></td>
        <td align="center"><?php echo $linea['notes'] ?></td>
    </tr>
<?php
}
?>